<?php
//从微信网站取回验证码图片
$username = $_GET['u'];
$url = "https://mp.weixin.qq.com/cgi-bin/verifycode?username={$username}&r=".time();

//必须绝对路径
$file = dirname(__FILE__).'/cookie/cookie_'.$username.'.txt';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt($curl, CURLOPT_TIMEOUT, 10 );   
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, $file);
$res = curl_exec ($curl);
curl_close ( $curl );
header("Content-type:image/jpeg");
echo $res;